from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-30 14:03:48.906803
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 30, May, 2022
Time: 14:03:54
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4685
Nobs: 672.000 HQIC: -49.8386
Log likelihood: 8332.64 FPE: 1.79379e-22
AIC: -50.0726 Det(Omega_mle): 1.57049e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.306147 0.059543 5.142 0.000
L1.Burgenland 0.107064 0.038534 2.778 0.005
L1.Kärnten -0.109929 0.020269 -5.423 0.000
L1.Niederösterreich 0.196794 0.080197 2.454 0.014
L1.Oberösterreich 0.127419 0.079337 1.606 0.108
L1.Salzburg 0.255786 0.041001 6.239 0.000
L1.Steiermark 0.045176 0.053722 0.841 0.400
L1.Tirol 0.104477 0.043513 2.401 0.016
L1.Vorarlberg -0.061258 0.038366 -1.597 0.110
L1.Wien 0.033024 0.070282 0.470 0.638
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.040913 0.126570 0.323 0.747
L1.Burgenland -0.030694 0.081913 -0.375 0.708
L1.Kärnten 0.040140 0.043087 0.932 0.352
L1.Niederösterreich -0.181847 0.170475 -1.067 0.286
L1.Oberösterreich 0.444139 0.168647 2.634 0.008
L1.Salzburg 0.284878 0.087155 3.269 0.001
L1.Steiermark 0.108278 0.114196 0.948 0.343
L1.Tirol 0.315332 0.092495 3.409 0.001
L1.Vorarlberg 0.023802 0.081555 0.292 0.770
L1.Wien -0.037282 0.149398 -0.250 0.803
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185939 0.030569 6.083 0.000
L1.Burgenland 0.089153 0.019783 4.506 0.000
L1.Kärnten -0.007975 0.010406 -0.766 0.443
L1.Niederösterreich 0.256669 0.041172 6.234 0.000
L1.Oberösterreich 0.153068 0.040731 3.758 0.000
L1.Salzburg 0.043690 0.021049 2.076 0.038
L1.Steiermark 0.024004 0.027580 0.870 0.384
L1.Tirol 0.085606 0.022339 3.832 0.000
L1.Vorarlberg 0.053414 0.019697 2.712 0.007
L1.Wien 0.117535 0.036082 3.257 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110058 0.030664 3.589 0.000
L1.Burgenland 0.044694 0.019845 2.252 0.024
L1.Kärnten -0.014219 0.010439 -1.362 0.173
L1.Niederösterreich 0.183713 0.041301 4.448 0.000
L1.Oberösterreich 0.325835 0.040858 7.975 0.000
L1.Salzburg 0.102026 0.021115 4.832 0.000
L1.Steiermark 0.108988 0.027666 3.939 0.000
L1.Tirol 0.097633 0.022409 4.357 0.000
L1.Vorarlberg 0.061775 0.019758 3.127 0.002
L1.Wien -0.021477 0.036195 -0.593 0.553
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119277 0.056965 2.094 0.036
L1.Burgenland -0.045517 0.036866 -1.235 0.217
L1.Kärnten -0.046177 0.019392 -2.381 0.017
L1.Niederösterreich 0.142858 0.076726 1.862 0.063
L1.Oberösterreich 0.160413 0.075903 2.113 0.035
L1.Salzburg 0.281615 0.039226 7.179 0.000
L1.Steiermark 0.053699 0.051396 1.045 0.296
L1.Tirol 0.165153 0.041629 3.967 0.000
L1.Vorarlberg 0.096425 0.036706 2.627 0.009
L1.Wien 0.074505 0.067240 1.108 0.268
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058931 0.044978 1.310 0.190
L1.Burgenland 0.031259 0.029109 1.074 0.283
L1.Kärnten 0.051470 0.015312 3.362 0.001
L1.Niederösterreich 0.204763 0.060581 3.380 0.001
L1.Oberösterreich 0.316773 0.059931 5.286 0.000
L1.Salzburg 0.041396 0.030972 1.337 0.181
L1.Steiermark 0.008827 0.040581 0.218 0.828
L1.Tirol 0.132375 0.032869 4.027 0.000
L1.Vorarlberg 0.067584 0.028982 2.332 0.020
L1.Wien 0.087239 0.053091 1.643 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168237 0.053768 3.129 0.002
L1.Burgenland 0.006993 0.034797 0.201 0.841
L1.Kärnten -0.065004 0.018304 -3.551 0.000
L1.Niederösterreich -0.090750 0.072420 -1.253 0.210
L1.Oberösterreich 0.200565 0.071643 2.799 0.005
L1.Salzburg 0.054938 0.037024 1.484 0.138
L1.Steiermark 0.239913 0.048512 4.945 0.000
L1.Tirol 0.502574 0.039293 12.790 0.000
L1.Vorarlberg 0.060230 0.034646 1.738 0.082
L1.Wien -0.075499 0.063466 -1.190 0.234
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150833 0.059832 2.521 0.012
L1.Burgenland 0.002597 0.038722 0.067 0.947
L1.Kärnten 0.060648 0.020368 2.978 0.003
L1.Niederösterreich 0.187321 0.080587 2.324 0.020
L1.Oberösterreich -0.061626 0.079722 -0.773 0.440
L1.Salzburg 0.206853 0.041200 5.021 0.000
L1.Steiermark 0.133153 0.053982 2.467 0.014
L1.Tirol 0.070883 0.043724 1.621 0.105
L1.Vorarlberg 0.143526 0.038552 3.723 0.000
L1.Wien 0.107568 0.070623 1.523 0.128
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375153 0.035310 10.625 0.000
L1.Burgenland -0.001430 0.022852 -0.063 0.950
L1.Kärnten -0.022112 0.012020 -1.840 0.066
L1.Niederösterreich 0.215436 0.047558 4.530 0.000
L1.Oberösterreich 0.224778 0.047048 4.778 0.000
L1.Salzburg 0.039868 0.024314 1.640 0.101
L1.Steiermark -0.015755 0.031858 -0.495 0.621
L1.Tirol 0.096405 0.025804 3.736 0.000
L1.Vorarlberg 0.055483 0.022752 2.439 0.015
L1.Wien 0.033922 0.041678 0.814 0.416
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038267 0.121201 0.177779 0.144426 0.104457 0.087687 0.040175 0.214111
Kärnten 0.038267 1.000000 -0.018472 0.135797 0.053166 0.091703 0.441531 -0.059394 0.094683
Niederösterreich 0.121201 -0.018472 1.000000 0.325054 0.132522 0.284748 0.079104 0.164092 0.303609
Oberösterreich 0.177779 0.135797 0.325054 1.000000 0.221876 0.312326 0.171680 0.152615 0.255367
Salzburg 0.144426 0.053166 0.132522 0.221876 1.000000 0.132241 0.100169 0.117153 0.133077
Steiermark 0.104457 0.091703 0.284748 0.312326 0.132241 1.000000 0.142908 0.120886 0.056209
Tirol 0.087687 0.441531 0.079104 0.171680 0.100169 0.142908 1.000000 0.074252 0.151475
Vorarlberg 0.040175 -0.059394 0.164092 0.152615 0.117153 0.120886 0.074252 1.000000 0.010353
Wien 0.214111 0.094683 0.303609 0.255367 0.133077 0.056209 0.151475 0.010353 1.000000